import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {getTimePeriodByPerson} from "@/views/attendance/attreissue/AttReissue.api";
import {reactive} from 'vue';
export const columnsAudit: BasicColumn[] = [
  {
    title: '学号',
    align:"center",
    dataIndex: 'code'
  },
  {
    title: '姓名',
    align:"center",
    dataIndex: 'name'
  },
  {
    title: '补登事由',
    align:"center",
    dataIndex: 'reissueReason'
  },
  {
    title: '补登日期',
    align:"center",
    dataIndex: 'reissueTime'
  },
  {
    title: '补登时间段',
    align:"center",
    dataIndex: 'attTimePeriodId_dictText'
  },
  {
    title: '上/下班卡',
    align:"center",
    dataIndex: 'clockIn',
    customRender:({text}) =>{
      return !text?"":(text=='1'?'上班卡':'下班卡')
    },
    width:100
  },
  {
    title: '最终结果',
    align:"center",
    dataIndex: 'status',
    customRender:({text}) =>{
      return !text?"":(text=='0'?'待审核':text=='1'?'通过':'未通过')
    },
  },
  {
    title: '我的审批',
    align:"center",
    dataIndex: 'applyResultResult',
    customRender:({text}) => {
      return  render.renderDict(text,'att_event_reg_status')
    },
  },
  {
    title: '申请时间',
    align:"center",
    dataIndex: 'createTime',
  },
/*  {
    title: '创建日期',
    align:"center",
    dataIndex: 'createTime',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
  },
  {
    title: '更新日期',
    align:"center",
    dataIndex: 'updateTime',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    }
  },*/
];

//列表数据
export const columns: BasicColumn[] = [
   {
    title: '学号',
    align:"center",
    dataIndex: 'code'
   },
   {
    title: '姓名',
    align:"center",
    dataIndex: 'name'
   },
/*   {
    title: '设备',
    align:"center",
    dataIndex: 'deviceName'
   },*/
   {
    title: '补登事由',
    align:"center",
    dataIndex: 'reissueReason'
   },
   {
    title: '补登日期',
    align:"center",
    dataIndex: 'reissueTime'
   },
  {
    title: '补登时间段',
    align:"center",
    dataIndex: 'attTimePeriodId_dictText'
  },
   {
    title: '上/下班卡',
    align:"center",
    dataIndex: 'clockIn',
    customRender:({text}) =>{
      return !text?"":(text=='1'?'上班卡':'下班卡')
    },
    width:100
   },
   {
    title: '最终结果',
    align:"center",
    dataIndex: 'status',
    customRender:({text}) =>{
      return !text?"":(text=='0'?'待审核':text=='1'?'通过':'未通过')
    },
   },
   {
    title: '申请时间',
    align:"center",
    dataIndex: 'createTime',
   },
  /* {
    title: '更新日期',
    align:"center",
    dataIndex: 'updateTime',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    }
   },*/
];
//查询数据
export const searchFormSchema: FormSchema[] = [

	{
      label: "学号",
      field: 'code',
      component: 'Input',
      //colProps: {span: 6},
 	},
  {
      label: "姓名",
      field: 'name',
      component: 'Input',
      //colProps: {span: 6},
  },

	{
      label: "状态",
      field: 'status',
      component: 'JDictSelectTag',
      componentProps:{
        options: [
          { label: '待审核', value: '0' },
          { label: '通过', value: '1' },
          { label: '未通过', value: '2' },
        ],
      },
      //colProps: {span: 6},
 	},
];

export const formSchemaAudit: FormSchema[] = [
  /*  {
      label: '人员',
      field: 'personId',
      required: true,
      component: 'JSelectPerson',
      componentProps: {
        labelKey: 'name',
        isRadioSelection: true
      },
      dynamicDisabled: ({ values }) => {
        return !!values.id;
      },
    },*/
  {
    label: '设备',
    field: 'deviceId',
    component: 'JSearchSelect',
    componentProps:{
      dict:"ss_device,device_name,id,device_type=2"
    },
    show:false,
  },
  {
    label: '补登时间',
    field: 'reissueTime',
    component: 'DatePicker',
    componentProps: {
      showTime: false,
      valueFormat: 'YYYY-MM-DD'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '时间不能为空!'},
      ];
    },
  },
  {
    label: '班次',
    field: 'clockIn',
    component: 'RadioGroup',
    componentProps:{
      options: [
        { label:'上班卡', value: '1' },
        { label:'下班卡', value: '2' },
      ],
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择班次!'},
      ];
    },
  },

  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps:{
      options: [
        { label: '待审核', value: '0' },
        { label: '通过', value: '1' },
        { label: '未通过', value: '2' },
      ],
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '状态不能为空!'},
      ];
    },
    show:false,
    defaultValue:'0'
  },
  {
    label: '补登事由',
    field: 'reissueReason',
    component:'InputTextArea',
    //属性
    componentProps:{
      //可以点击清除图标删除内容
      allowClear: true,
      //是否展示字数
      showCount: true,
      //自适应内容高度，可设置为 true | false 或对象：{ minRows: 2, maxRows: 6 }
      autoSize:{
        //最小显示行数
        minRows: 3,
        //最大显示行数
        maxRows: 5
      },
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请填写原因'},
      ];
    },
  },

  {
    label: '删除',
    field: 'delFlag',
    component: 'Input',
    show:false,
    defaultValue:'0'
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
const options = reactive([]);
export const changeTimePeriod = async (e)=> {
  let tp = await getTimePeriodByPerson({reissueTime:e});
  console.log(tp);
  options.splice(0,options.length);
  for (let i = 0; i < tp.length; i++) {
    let op = {};
    op.value = tp[i].id;
    op.label = tp[i].name + " " + tp[i].workTime + "至" + tp[i].leaveTime;
    options.push(op);
  }
};
//表单数据
export const formSchema: FormSchema[] = [
/*  {
    label: '人员',
    field: 'personId',
    required: true,
    component: 'JSelectPerson',
    componentProps: {
      labelKey: 'name',
      isRadioSelection: true
    },
    dynamicDisabled: ({ values }) => {
      return !!values.id;
    },
  },*/
  {
    label: '设备',
    field: 'deviceId',
    component: 'JSearchSelect',
    componentProps:{
       dict:"ss_device,device_name,id,device_type=2"
    },
    show:false,
  },

  {
    label: '补登时间',
    field: 'reissueTime',
    component: 'DatePicker',
    componentProps: (formModel)=>{
      return {
        showTime: false,
        valueFormat: 'YYYY-MM-DD',
        onChange:changeTimePeriod,
      }
     },
     dynamicRules: ({model,schema}) => {
           return [
                  { required: true, message: '时间不能为空!'},
           ];
      },
  },
  {
    label: '时间段',
    field: 'attTimePeriodId',
    component: 'Select',
    componentProps:{
      options:options,
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择时间段!'},
      ];
    },
  },
  {
    label: '上/下班卡',
    field: 'clockIn',
    component: 'RadioGroup',
    componentProps:{
      options: [
                { label:'上班卡', value: '1' },
                { label:'下班卡', value: '2' },
              ],
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请选择班次!'},
          ];
     },
  },
  
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps:{
       options: [
        { label: '待审核', value: '0' },
        { label: '通过', value: '1' },
        { label: '未通过', value: '2' },
       ],
     },
     dynamicRules: ({model,schema}) => {
           return [
                  { required: true, message: '状态不能为空!'},
           ];
      },
      show:false,
      defaultValue:'0'
  },
  {
    label: '补登事由',
    field: 'reissueReason',
    component:'InputTextArea',
          //属性
      componentProps:{
        //可以点击清除图标删除内容
        allowClear: true,
        //是否展示字数
        showCount: true,
        //自适应内容高度，可设置为 true | false 或对象：{ minRows: 2, maxRows: 6 }
        autoSize:{
          //最小显示行数
          minRows: 3,
          //最大显示行数
          maxRows: 5
        },
      },
      dynamicRules: ({model,schema}) => {
            return [
                   { required: true, message: '请填写原因'},
            ];
       },
  },

  {
    label: '删除',
    field: 'delFlag',
    component: 'Input',
    show:false,
    defaultValue:'0'
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  createTime: {title: '创建日期',order: 0,view: 'date', type: 'string',},
  updateTime: {title: '更新日期',order: 1,view: 'datetime', type: 'string',},
  personId: {title: '人员id',order: 2,view: 'text', type: 'string',},
  deviceId: {title: '设备id',order: 3,view: 'number', type: 'number',},
  reissueReason: {title: '不登事由',order: 4,view: 'text', type: 'string',},
  status: {title: '状态',order: 5,view: 'list', type: 'string',},
  delFlag: {title: '删除',order: 6,view: 'text', type: 'string',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
